const { join } = require('path');
const { default: UnoCSS } = require('@unocss/webpack')
const FriendlyErrorsWebpackPlugin = require('@nuxt/friendly-errors-webpack-plugin')
module.exports = {
    entry: {
        [`demo3`]: join(__dirname, `src/demo3.ts`),
        [`demo4`]: join(__dirname, `src/demo4.ts`),
        [`zhuabao`]: join(__dirname, `src/zhuabao.ts`),
    },
    mode: "production",
    watch: true,
    optimization: {
        minimize: true,
        sideEffects: false,
        splitChunks: false,
        realContentHash: true
    },
    output: {
        path: join(__dirname, "../dist/public/mobile"),
        filename: '[name].js',
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js', '.scss', '.css']
    },
    devtool: false,
    module: {
        rules: [
            {
                test: /\.(png|jpg|gif|html)$/,
                use: [{
                    loader: 'file-loader',
                    options: {}
                }]
            },
            {
                test: /\.svg$/,
                use: ['@svgr/webpack'],
            },
            { test: /\.txt$/, use: 'raw-loader' },
            {
                test: /\.css$/,
                use: ["style-loader", "css-loader"],
            },
            {
                test: /\.less$/,
                use: ["style-loader", "css-loader", "less-loader"],
            },
            {
                test: /\.s[ac]ss$/,
                use: ["style-loader", "css-loader", "sass-loader"],
            },
            {
                test: /\.[cm]?ts|tsx$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [
                            '@babel/preset-env',
                            '@babel/preset-react',
                            '@babel/preset-typescript',
                        ],
                        plugins: [
                            "babel-plugin-transform-typescript-metadata",
                            ["@babel/plugin-proposal-decorators", { "version": "legacy" }],
                            ['@babel/plugin-transform-class-properties', { "loose": true }],
                            ["@babel/plugin-transform-private-methods", { "loose": true }],
                            ["@babel/plugin-transform-private-property-in-object", { "loose": true }],
                        ]
                    },
                },
            }
        ]
    },
    plugins: [
        UnoCSS(),
        new FriendlyErrorsWebpackPlugin()
    ]
}
